// webpack.config.client.js
const path = require("path");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const { WebpackManifestPlugin } = require("webpack-manifest-plugin");

module.exports = {
  // 配置名
  name: "client",
  entry: {
    // 应用程序的入口文件地址
    client: path.resolve(__dirname, "client/client.tsx"),
  },
  // 启动生产环境的优化
  mode: "production",
  output: {
    // 指定输出文件的 地址
    //输出文件名为[name].[contenthash].js，其中[contenthash]是基于文件内容生成的哈希值，用于缓存 busting。
    // publicPath设置为空字符串，表示资源的公共路径
    path: path.resolve(__dirname + "/dist/static"),
    filename: "[name].[contenthash].js",
    publicPath: "",
  },
  // 配置模块解析时支持的扩展名
  resolve: {
    extensions: [".ts", ".tsx", ".js"],
    alias: {
      "@": path.resolve(__dirname, "./"),
    },
  },
  // 构建的为 web 环境支持
  target: "web",
  module: {
    rules: [
      {
        test: /\.tsx?$/,
        loader: "ts-loader",
        options: {
          configFile: "tsconfig.client.json",
        },
      },
    ],
  },
  // 插件
  plugins: [new CleanWebpackPlugin(), new WebpackManifestPlugin()],
};
